package guowenlong.golf.ui.court;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import guowenlong.golf.R;
import guowenlong.golf.ui.friend.myfriends.SearchFriendsActivity;
import guowenlong.golf.ui.home.TabAdapter;
import java.util.ArrayList;
import java.util.List;

/**
 * des   : 描述
 * author: Administrator
 * email : guowenlong20000@gmail.com
 * time  : 2017年04月14日 下午 5:27.
 */

public class CourtListActivity extends FragmentActivity {

  @BindView(R.id.tv_back)
  TextView tvBack;
  @BindView(R.id.tl_myteam_details)
  TabLayout tlMyteamDetails;
  @BindView(R.id.vp_myteam_details)
  ViewPager vpMyteamDetails;
  @BindView(R.id.btn_court_search)
  Button btnCourtSearch;
  private FragmentPagerAdapter fAdapter;
  private List<Fragment> list_fragment;
  private List<String> list_title;
  private CourtNearFragment mCourtNearFragment1;
  private CourtNearFragment mCourtNearFragment2;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_court_list);
    ButterKnife.bind(this);
    initData();
  }

  private void initData() {
    mCourtNearFragment1 = new CourtNearFragment();
    mCourtNearFragment2 = new CourtNearFragment();
    list_fragment = new ArrayList<>();
    list_fragment.add(mCourtNearFragment1);
    list_fragment.add(mCourtNearFragment2);

    list_title = new ArrayList<>();
    list_title.add("附近");
    list_title.add("收藏");
    tlMyteamDetails.setTabMode(TabLayout.MODE_FIXED);
    tlMyteamDetails.addTab(tlMyteamDetails.newTab().setText(list_title.get(0)));
    tlMyteamDetails.addTab(tlMyteamDetails.newTab().setText(list_title.get(1)));

    fAdapter = new TabAdapter(getSupportFragmentManager(), list_fragment, list_title);

    vpMyteamDetails.setAdapter(fAdapter);
    tlMyteamDetails.setupWithViewPager(vpMyteamDetails);
  }

  @OnClick({R.id.tv_back, R.id.btn_court_search})
  public void onViewClicked(View view) {
    switch (view.getId()) {
      case R.id.tv_back:
        finish();
        break;
      case R.id.btn_court_search:
        startActivity(new Intent(this, SearchFriendsActivity.class));
        break;
    }
  }
}
